var registStr='<br/><br/>用户名称： <input  type="text" id="user_name" class="normalinputbox " onBlur="checkUserOrMail(\'user_name\',\'u\')"/><br/><br/>邮箱地址： <input  type="text" id="user_email" onblur="email_verify(\'user_email\')"  class="normalinputbox "/>'+
'<br/><br/>登录密码： <input type="password" id="user_password" /> <DIV id=psContainer>'+
'<DIV class=progressbar></DIV></DIV><DIV id=cssrain></DIV><br/><br/>确认密码： <input  type="password" id="user_confirmpassword"  class="normalinputbox " onkeyup="checkReconfirmPassword(\'user_password\',\'user_confirmpassword\')"/>  <br/><br/>验证码：&nbsp;&nbsp;&nbsp;&nbsp; <input  type="text" id="user_validatecode"  class="shortinputbox " /> <img src="validatecode.do?type=vc"/><br/><br/>  <input  type="image" src="images/index/sb.gif" onClick="registUser()"/>&nbsp;&nbsp;&nbsp;&nbsp;<input  type="image" src="images/index/rs.gif"/>';


var cona=false;//全局变量，代表用户名是否符合要求
var conb=false;//全局变量，邮箱是否符合要求
var conc=false;//全局变量，代表密码是否符合要求


$(document).ready( function() {

//init hialert 
                $("#button_register").click( function() {
					hiBox('#div_register', '用户注册','450','300','','.a_close');
					document.all.popup_message.innerHTML=registStr;
					pwc();
				});
				});


			
	   function  pwc(){
			
		$('#user_password').keyup(function(){
				var strength = getStrength($(this).val());
				var width = (100/32)*strength;
				var colors=new Array("#FF0000","#FFCC00","#33CCFF");
				 //alert(width)
				 if(width<30){
			        $('.progress').css("background-color",colors[0]);
				 	$(".progressbar").progression({ Current: width 
				 });
                 
				   $("#cssrain").html("强度弱!");   
				
				 }
				 else if(width>30&&width<75){
				 	  $('.progress').css("background-color",colors[1]);
 	                  $(".progressbar").progression({ Current: width 
				    });
				
					$("#cssrain").html("强度一般!"); 
					  
				 }
				 else if(width>75){
				       $('.progress').css("background-color",colors[2]);
                       	$(".progressbar").progression({ Current: width 
				           });
				      $("#cssrain").html("强度强!");   
				 }
				
        
                });
		
			}
			
			
			
			
			
			
function email_verify(id)
{
 var email=document.getElementById(id).value;
  
 var reg=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)$/;
 if(!email.match(reg))
  {
	  document.getElementById(id).className='wronginputbox';
  
  }else{
	  document.getElementById(id).className='normalinputbox'; 
	  checkUserOrMail(id,'m');
	  
  }
 }
 
 
 
 function checkReconfirmPassword(pwid,repwid){
	 var pw= document.getElementById(pwid).value;
	 var repw=document.getElementById(repwid).value;
	 if(pw!=repw){
		  document.getElementById(repwid).className='wronginputbox';
		  conc=false;
		 }else{
			 document.getElementById(repwid).className='normalinputbox'; 
			 conc=true;
			 
		 }
 
 }
 
 
 
 function registUser(){
	   var validatecode=document.getElementById('user_validatecode').value;
       var username=dwr.util.getValue("user_name");
       var useremail=dwr.util.getValue("user_email");
       var userpassword=dwr.util.getValue("user_password");
       var user= {userName:username, userEmail:useremail, userPassword:userpassword};
		  
		if(cona==true&&conb==true&&conc==true){
        IndexAction.registUser(validatecode,user,function(data){
        	hiAlert(data, '恭喜');
        	}); 
		}else{
			alert("请按要求填写表单!");
			alert(cona+""+conb+""+conc);
		}
 }
 
 function checkUserOrMail(inputbox,type){
	 var ob=document.getElementById(inputbox).value;
	 if(ob!=""){
	 IndexAction.checkUserOrMail(ob,type,function(data){
		 if(data=="a"||data=="c"){
			 document.getElementById(inputbox).className='wronginputbox';
			 
		 }else{
			 
			 document.getElementById(inputbox).className='normalinputbox';
			 if(data=="b"){
				  cona=true;
				
			 }else if(data=="d"){
				 conb=true;
			 }
		 }
			 });
	 }else if(ob==""){
		 checkInputBoxValue(inputbox,'');
	 }
	 
	 
	 
 }
 
 function checkInputBoxValue(inputbox,tipdiv){
	 var ob=document.getElementById(inputbox).value;
	 if(ob==""){
		 document.getElementById(inputbox).className='wronginputbox';
		if(inputbox=="user_name"){
			cona=false;
		}else if(inputbox=="user_email"){
			conb=false;
		}else if(inputbox=="user_password"){
			conc=false;
		}else if(inputbox=="user_confirmpassword"){
			conc=false;
		}
		 
	 }
	 
	 
 }
 
 function checkBeforeUserLogin(){
	 var un=document.getElementById("userName").value;
	 var pw=document.getElementById("userPassword").value;
	 var cd=document.getElementById("login_validatecode").value;
 if(un!=""&&pw!=""&&cd!=""){
	 document.userLoginForm.Subimt;
 }else{
 alert("用户名，密码，验证码都不能为空！");
 }
 
 }
 
 function clearBoxValue(boxid){
	 dwr.util.setValue(boxid, "");
 }
 